import json

from pydantic import BaseModel
from .request_item import RequestItem


class ResponseItem(BaseModel):
    url: str = ""
    status_code: int = 0
    content: list = []
    headers: dict = None
    cookies: dict = None

    errors: Exception = None

    request_item: RequestItem

    class Config:
        arbitrary_types_allowed = True

    @property
    def buffer(self) -> bytes:
        return bytes(self.content)

    @property
    def text(self) -> str:
        return self.buffer.decode()

    @property
    def data(self) -> dict:
        return json.loads(self.buffer)
